package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.BsDrugEntityVo;
import io.renren.modules.app.entity.BsDrugregisEntity;
import io.renren.modules.app.service.BsDrugregisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 用药登记表
 *
 */
@RestController
@RequestMapping("tb_bs_drugregis/bsdrugregis")
public class BsDrugregisController {
    @Autowired
    private BsDrugregisService bsDrugregisService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("tb_bs_drugregis:bsdrugregis:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsDrugregisService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("tb_bs_drugregis:bsdrugregis:info")
    public R info(@PathVariable("id") Long id){
		BsDrugregisEntity bsDrugregis = bsDrugregisService.getById(id);

        return R.ok().put("bsDrugregis", bsDrugregis);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tb_bs_drugregis:bsdrugregis:save")
    public R save(@RequestBody BsDrugregisEntity bsDrugregis){
        bsDrugregisService.saveDrugRegis(bsDrugregis);
		//bsDrugregisService.save(bsDrugregis);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tb_bs_drugregis:bsdrugregis:update")
    public R update(@RequestBody BsDrugregisEntity bsDrugregis){
        bsDrugregisService.updateDrugRegis(bsDrugregis);
		//bsDrugregisService.updateById(bsDrugregis);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tb_bs_drugregis:bsdrugregis:delete")
    public R delete(@RequestBody Long[] ids){
		bsDrugregisService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 获取药品
     */
    @RequestMapping("/getDrug")
    public R getDrug(){
        List<BsDrugEntityVo> list = bsDrugregisService.getDrug();
        return R.ok(list) ;
    }

}
